from typing import List
from collections import defaultdict

class Solution:

    def leastBricks(self, wall: List[List[int]]) -> int:
        result_dict = defaultdict(int)
        for row in wall:
            comsum = 0
            for j in range(0, len(row)-1):
                comsum += row[j]
                if comsum in result_dict:
                    result_dict[comsum] += 1
                else:
                    result_dict[comsum] = 1
        return len(wall) - max(result_dict.values(), default=0)


wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]
print(Solution().leastBricks(wall))


# wall = [[1],[1],[1]]
# print(Solution().leastBricks(wall))



